package com.aaa.service.fpa.impl;

import cn.hutool.core.util.ObjectUtil;

import com.aaa.dao.fpa.TestPlanFpaDao;
import com.aaa.dao.view.ViewsDao;
import com.aaa.entity.fpa.TestPlanFpa;
import com.aaa.entity.system.PageOrder;
import com.aaa.service.fpa.TestPlanFpaService;
import com.aaa.utils.MyRandom;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 测试计划fpa(TestPlanFpa)表服务实现类
 *
 * @author makejava
 * @since 2022-08-31 21:22:06
 */
@Service("testPlanFpaService")
public class TestPlanFpaServiceImpl implements TestPlanFpaService {
    @Autowired
    private TestPlanFpaDao testPlanFpaDao;

    @Autowired
    ViewsDao viewsDao;

    /**
     * 查询所有及分页
     *
     * @param testPlanFpa
     * @return
     */
    @Override
    public Page queryAll(PageOrder pageOrder, TestPlanFpa testPlanFpa) {
        PageHelper.startPage(pageOrder.getPage(), pageOrder.getLimit());
        if (ObjectUtil.isNotEmpty(pageOrder.getField())) {
            PageHelper.orderBy(pageOrder.getFieldOrder());
        }
        List<TestPlanFpa> tpa = testPlanFpaDao.queryAll(testPlanFpa);
        Page pageResult = (Page) tpa;
        return pageResult;
    }

    @Override
    public int insert(TestPlanFpa testPlanFpa) {
        List<Integer> list = viewsDao.queryView();
        int myRan = MyRandom.myRan(list);
        testPlanFpa.setTestCode(myRan);
        return testPlanFpaDao.insert(testPlanFpa);
    }

    @Override
    public int update(TestPlanFpa testPlanFpa) {
        return testPlanFpaDao.update(testPlanFpa);
    }

    @Override
    public boolean deleteById(int[] id) {
        return testPlanFpaDao.deleteById(id);
    }

    @Override
    public boolean repetitionName(TestPlanFpa testPlanFpa) {
        List<TestPlanFpa> planFpas = testPlanFpaDao.repetitionName(testPlanFpa);
        if (ObjectUtil.isEmpty(planFpas)) {
            return true;
        } else {
            return false;
        }
    }

}
